<template>
  <div class="page-cont">
    <van-nav-bar
      title="我的"
    />
    <div class="list">
      <van-contact-card
        type="edit"
        :name="userInfo.username"
        :tel="userInfo.mobile"
        @click="onEditUser"
      />
      <van-cell
        title="修改密码"
        is-link
        @click="$router.push('/my/pwd')"
      />
      <van-cell
        title="关于我们"
        is-link
        @click="$router.push('/my/about')"
      />
      <van-cell
        title="分享APP"
        is-link
        @click="$router.push('/my/share')"
      />
      <van-cell
        title="当前版本"
        value="V1.0.0"
      />
      <van-cell
        title="检查新版本"
        is-link
        @click="checkVersion"
      />
      <van-cell
        is-link
        @click="logout"
      >
        <template #title>
          <span style="color:red;">退出登陆</span>
        </template>
        <template #right-icon />
      </van-cell>
    </div>

    <bottom-nav active="my" />
  </div>
</template>

<script>
import BottomNav from '@/components/BottomNav/index.vue'
import { mapState } from 'vuex'

export default {
  name: "MyPage",
  components: {
    BottomNav
  },
  computed: {
    ...mapState({
      userInfo: state => state.user.userInfo
    }),
  },
  data() {
    return {};
  },
  methods: {
    onEditUser() {
      this.$router.push('/my/edit')
    },
    checkVersion() {
      this.$toast.success(' 已是最新版本')
    },
    logout() {
      this.$dialog
        .confirm({
          title: "提示",
          message: "您确定要退出登陆吗?",
        })
        .then(async () => {
          // 删除缓存
          this.$store.state.user.userInfo = null
          Object.keys(this.$store.state.pre).forEach((key) => {
            console.log(this.$store.state.pre[key])
            this.$store.state.pre[key] = []
          })
          Object.keys(this.$store.state.cars).forEach((key) => {
            console.log(this.$store.state.cars[key])
            this.$store.state.cars[key] = []
          })
          
          this.libs.store.delItem('userinfo')
          this.libs.store.delItem('token')
          this.$router.replace('/login')
        })
        .catch(() => {});
    }
  }
};
</script>

<style lang="scss" scoped>
@import "./style.scss";
</style>
